import React, { PureComponent } from 'react'

import { connect } from 'react-redux'
import { addAction } from '../store/counter/actionCreators'
import { getHomeMultidataAction } from '../store/home/actionCreators'
import axios from 'axios'
class Home extends PureComponent {
  componentDidMount() {
    this.props.getHomeMultidata()
  }
  render() {
    return (
      <div>
        <h1>Home</h1>
        <h2>当前计数:{this.props.counter}</h2>
        <button onClick={(e) => this.props.increment()}>+1</button>
        <button onClick={(e) => this.props.addCounter()}>+5</button>
      </div>
    )
  }
}
const mapStateToProps = (state) => ({
  counter: state.counter
})

const mapDispatchToProps = (dispatch) => ({
  increment() {
    dispatch(addAction(1))
  },
  addCounter() {
    dispatch(addAction(5))
  },
  getHomeMultidata() {
    dispatch(getHomeMultidataAction())
  }
})
export default connect(mapStateToProps, mapDispatchToProps)(Home)
